package com.stupro.cjlu.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.common.vo.TeacherCourseItemVO;
import com.stupro.cjlu.entity.Course;
import com.stupro.cjlu.entity.Studentcourse;
import com.stupro.cjlu.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CourseDAO extends BaseDAO {

    @Autowired
    private CourseMapper courseMapper;

    public int getCourseCountByTeacherId(int teacherId) {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Course::getTeaID, teacherId);
        return courseMapper.selectCount(wrapper);
    }

    public int delById(int id) {
        return courseMapper.deleteById(id);
    }

    public int addCourse(Course course) {
        int result = 0;
        try {
            result = courseMapper.insert(course);
        } catch (Exception e) {

        } finally {
            return result;
        }

    }


    public Course get(int id) {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper();
        wrapper.eq(Course::getCoID, id);
        return courseMapper.selectOne(wrapper);
    }

    public int insert(Course entity) {
        return courseMapper.insert(entity);
    }

    public int count(Integer teacherId, String name) {
        return courseMapper.count(teacherId, name);
    }



}
